package org.indp.mongowl.ui.container;

import com.mongodb.DBObject;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import org.bson.types.ObjectId;

import java.util.Collection;

/**
 *
 */
public class DBObjectItem implements Item {

    private final DBObject object;

    public DBObjectItem(DBObject object) {
        this.object = object;
    }

    @Override
    public Property getItemProperty(Object id) {
        switch (id.toString()) {
            case MongoCursorContainer.OBJECT:
                return new DBObjectProperty(object);
            case MongoCursorContainer.ID:
                return new ObjectIdProperty((ObjectId) object.get("_id"));
        }
        return null;
    }

    @Override
    public Collection<?> getItemPropertyIds() {
        return MongoCursorContainer.PROPERTY_IDS;
    }

    @Override
    public boolean addItemProperty(Object id, Property property) throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean removeItemProperty(Object id) throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }
}
